cap log close

global path = "****"

local name= "coverage_tables"
local date = "051820"

global logname = "$path/`name'_`date'.log"

clear
set more off
set matsize 11000
cd "$path"
log using "$logname", replace

use "$path/Data/penalty_sample_prepcode.dta", clear

replace age_2017=0 if age_2017<0

gen cov2016_11 = (covered2016 - any_dec == 11)
gen age_45_64 = age_2017 < 65 & age_2017 >= 45

*Table: Effect of Treatment on Coverage-randomization block controls (overall, all16, notall16)

*Panel A: All Ages

*Column 1: any_coverage1718 (overall)
reghdfe any_covered1718 treatment, vce(cl tin) absorb(cluster1)
eststo
estadd scalar nobs e(N)
summ `e(depvar)' if e(sample)& treatment==0
estadd scalar ymean=r(mean)*100
estimates save "$path/cov_effect_cluster1_`date'.ster", replace
				
*Column 2: coverage1718 (overall)
reghdfe covered1718 treatment, vce(cl tin) absorb(cluster1)
eststo
estadd scalar nobs e(N)
summ `e(depvar)' if e(sample)& treatment==0
estadd scalar ymean=r(mean)
estimates save "$path/cov_effect_cluster1_`date'.ster", append

*Column 3: any_coverage1718 (all16)
reghdfe any_covered1718 treatment if cov2016_11 == 1, vce(cl tin) absorb(cluster1)
eststo
estadd scalar nobs e(N)
summ `e(depvar)' if e(sample)& treatment==0
estadd scalar ymean=r(mean)*100
estimates save "$path/cov_effect_cluster1_`date'.ster", append
				
*Column 4: coverage1718 (all16)
reghdfe covered1718 treatment if cov2016_11 == 1, vce(cl tin) absorb(cluster1)
eststo
estadd scalar nobs e(N)
summ `e(depvar)' if e(sample)& treatment==0
estadd scalar ymean=r(mean)
estimates save "$path/cov_effect_cluster1_`date'.ster", append
				
*Column 5: any_coverage1718 (notall16)
reghdfe any_covered1718 treatment if notall16 == 1, vce(cl tin) absorb(cluster1)
eststo
estadd scalar nobs e(N)
summ `e(depvar)' if e(sample)& treatment==0
estadd scalar ymean=r(mean)*100
estimates save "$path/cov_effect_cluster1_`date'.ster", append
				
*Column 6: coverage1718 (notall16)
reghdfe covered1718 treatment if notall16 == 1, vce(cl tin) absorb(cluster1)
eststo
estadd scalar nobs e(N)
summ `e(depvar)' if e(sample)& treatment==0
estadd scalar ymean=r(mean)
estimates save "$path/cov_effect_cluster1_`date'.ster", append
				
*Panel B: Ages 45-64

*Column 1: any_coverage1718 (overall)
reghdfe any_covered1718 treatment if age_45_64 == 1, vce(cl tin) absorb(cluster1)
eststo
estadd scalar nobs e(N)
summ `e(depvar)' if e(sample)& treatment==0
estadd scalar ymean=r(mean)*100
estimates save "$path/cov_effect_cluster1_`date'.ster", append
				
*Column 2: coverage1718 (overall)
reghdfe covered1718 treatment if age_45_64 == 1, vce(cl tin) absorb(cluster1)
eststo
estadd scalar nobs e(N)
summ `e(depvar)' if e(sample)& treatment==0
estadd scalar ymean=r(mean)
estimates save "$path/cov_effect_cluster1_`date'.ster", append

*Column 3: any_coverage1718 (all16)
reghdfe any_covered1718 treatment if cov2016_11 == 1 & age_45_64 == 1, vce(cl tin) absorb(cluster1)
eststo
estadd scalar nobs e(N)
summ `e(depvar)' if e(sample)& treatment==0
estadd scalar ymean=r(mean)*100
estimates save "$path/cov_effect_cluster1_`date'.ster", append
				
*Column 4: coverage1718 (all16)
reghdfe covered1718 treatment if cov2016_11 == 1 & age_45_64 == 1, vce(cl tin) absorb(cluster1)
eststo
estadd scalar nobs e(N)
summ `e(depvar)' if e(sample)& treatment==0
estadd scalar ymean=r(mean)
estimates save "$path/cov_effect_cluster1_`date'.ster", append
				
*Column 5: any_coverage1718 (notall16)
reghdfe any_covered1718 treatment if notall16 == 1 & age_45_64 == 1, vce(cl tin) absorb(cluster1)
eststo
estadd scalar nobs e(N)
summ `e(depvar)' if e(sample)& treatment==0
estadd scalar ymean=r(mean)*100
estimates save "$path/cov_effect_cluster1_`date'.ster", append
				
*Column 6: coverage1718 (notall16)
reghdfe covered1718 treatment if notall16 == 1 & age_45_64 == 1, vce(cl tin) absorb(cluster1)
eststo
estadd scalar nobs e(N)
summ `e(depvar)' if e(sample)& treatment==0
estadd scalar ymean=r(mean)
estimates save "$path/cov_effect_cluster1_`date'.ster", append
					

log close

